package com.nondo.rdp.auth.common;

import com.alibaba.fastjson.JSONObject;
import com.nondo.rdp.auth.domain.Message;
import com.nondo.rdp.core.model.Notification;

public class MessageCoverter {
	private static final int LENGHT =48;

	public static Notification toNotification(Message message) {
		Notification notification = new Notification();
		notification.setTitle(message.getTitle());
		String content = message.getContent();
		String body = content.replaceAll("<.*?>", "");
		if (body.length() > LENGHT) {
			notification.setBody(body.substring(0, LENGHT));
		} else {
			notification.setBody(body);
		}
		JSONObject extraParamsJson = new JSONObject();
		extraParamsJson.put("msgId", message.getId());
		extraParamsJson.put("umid", message.getUmid());
		extraParamsJson.put("extra", message.getExtra());
		extraParamsJson.put("method", message.getMethod());
		notification.setExtParameters(extraParamsJson.toJSONString());
		System.out.println(JSONObject.toJSON(notification).toString());
		return notification;
	}

}
